/*
	parent: show 26 digist
	child1: show 26 upper characters
	child2: show 26 lower characters
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include "Head/error.h"

int main(int argc, char * argv[]) {
	pid_t pid1, pid2;
	int i;

	// while(!(pid1 = fork()));

	pid1 = fork();
	if( pid1 == 0) {
		fprintf(stdout, "This is child process 1, pid=%d\n", getpid());
		for(i='A'; i<='Z'; i++) {
			fprintf(stdout, "Child process 1 print: %c\n", (char)i);
			sleep(1);
		}
	} else {
		pid2 = fork();
		if( pid2 == 0 ) {
			fprintf(stdout, "This is child process 2, pid=%d\n", getpid());
			for(i='a'; i<='z'; i++) {
				fprintf(stdout, "Child process 2 print: %c\n", (char)i);
				sleep(1);
			}
		} else {
			wait(0);
			fprintf(stdout, "This is parent process, pid=%d\n", getpid());
			for(i=1; i<=26; i++) {
				fprintf(stdin, "Parent process print: %d\n", i);
				sleep(1);
				exit(0);
			}
		}
	}

	return 0;
}
